<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>外卖超级助手</title>
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/style/login.css">
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/style/css/bootstrap.min.css">
<script
	src="${pageContext.request.contextPath}/js/lib/jquery-1.9.1.min.js"></script>
<script src="${pageContext.request.contextPath}/js/lib/jquery.md5.js"></script>
<script src="${pageContext.request.contextPath}/js/lib/bootstrap.min.js"></script>
<script
	src="${pageContext.request.contextPath}/js/lib/bootstrap-bootbox/bootbox.min.js"></script>
<script src="${pageContext.request.contextPath}/js/src/navtive.js"
	type="text/javascript"></script>
</head>

<body style="background-color: #15B4A2;">
	<div id="login">
		<div class="alert alert-success" style="padding: 10px; width: 280px;">
			如果您已经注册，请进行登录》<a href="${pageContext.request.contextPath}">登录</a>
		</div>
		<div class="formParent">
			<div id="register" class="loginForm">
				<form id="form">
					<input type="hidden" name="appType" value="appc">
					<div class="loginName">
						<label>用户名:</label> <input type="text" value="" class="userName"
							name="username">
					</div>
					<div class="loginPassword">
						<label>密码:</label> <input type="password" class="password"
							name="pwd" value="">
					</div>
					<div class="loginBtn">
						<input type="button" value="注册" class="btn btn-primary" id="btn"
							style="height: 30px; margin-left: 200px;">
					</div>
				</form>
			</div>
		</div>
	</div>
</body>
</html>
<script>
	$("#btn").click(function() {
		var $_userName = $(".userName");
		var $_password = $(".password");
		var tip = "";
		if ($_userName.val() == "") {
			tip = "账号不能为空";
			bootbox.alert(tip);
			return;
		} else if ($_password.val() == "") {
			tip = "密码不能为空";
			bootbox.alert(tip);
			return;
		}
		register($_userName.val(), $.md5($_password.val()))
	});

	function register(username, pwd) {
		var params = {
			"username" : username,
			"pwd" : pwd,
			"remenber" : 0
		};
		$
				.ajax({
					url : "${pageContext.request.contextPath}/admin/register.do",
					type : "post",
					dataType : "json",
					data : params,
					async : false,
					success : function(data) {
						if (data.flag == 1) {
							var url = "${pageContext.request.contextPath}/admin/index.do";
							window.location = url;
							var user = JSON.stringify(params);
							nativeSaveUserInfo(user);
							alert(user);
						} else {
							bootbox.alert(data.tip);
						}
					},
					error : function() {
						bootbox.alert("ajax错误");
					}
				});
	}
</script>
